-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cas2v2/cba 130 search by crn #2848
Conversation
get: | ||
tags: | ||
- People operations | ||
summary: Searches for a Person by their CRN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you define operationId
here you can generate a nicer controller function name .e.g
operationId: searchByCrn
Same goes for other endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
override fun peopleSearchGet(nomsNumber: String): ResponseEntity<Person> { | ||
val currentUser = nomisUserService.getUserForRequest() | ||
override fun peopleSearchByCrnCrnGet(crn: String): ResponseEntity<Person> { | ||
val deliusUser = cas2v2UserService.getUserForRequest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably we know this is a delius user because of the roles this endpoint is limited to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
|
||
val probationOffenderResult = offenderService.getPersonByNomsNumber(nomsNumber, currentUser) | ||
val personInfo = deliusOffenderService.getPersonInfoResult(crn, deliusUser.username, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll see this is complaining because you should be using this version instead:
fun getPersonInfoResult(
crn: String,
limitedAccessStrategy: LimitedAccessStrategy,
)
To enable this add something like the following to the bottom of OffenderService (this may not compile, hopefully you get the idea!)
fun Cas2v2UserEntity.limitedAccessStrategy() = when(userType) {
DELIUS -> LimitedAccessStrategy.ReturnRestrictedIfLimitedAccess(this.username)
else -> error("Can't provide strategy for users of type $userType")
}
And then use the extension function on the current user to get the strategy e.g.
deliusOffenderService.getPersonInfoResult(crn, deliusUser.limitedAccessStrategy())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -39,6 +39,51 @@ class OffenderService( | |||
|
|||
private val log = LoggerFactory.getLogger(this::class.java) | |||
|
|||
fun getPersonByNomsNumberAndActiveCaseLoadId(nomsNumber: String, activeCaseLoadId: String): ProbationOffenderSearchResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is the same as getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity)
but instead of passing a NomisUserEntity
(that is deprecated), you instead pass in the actual value from NomisUserEntity
that is required (Active Case ID)?
If that's the case, pretty much all of this code is common and can be shared. Could you not delete all of the body of getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity)
and just delegate to your new function e.g.
fun getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity) = getPersonByNomsNumberAndActiveCaseLoadId(nomsNumber, currentUser.activeNomisCaseloadId)
This means that no more unit tests on the service would be required (as they probably are currently)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
@Nested | ||
inner class WhenSuccessfulCRN { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the outline for this class there's a top level Cas2v2PeopleSearchGet
class containing these 4 inner classes. I think that top level one should be renamed to SearchByNomisId
and contain the two existing inner classes.
There should then be another top level inner class called SearchByCrn
which contains the two new inner classes
e.g.
Cas2v2PersonSearchTest
SearchByNomisId
WhenThereIsAnError
WhenSuccesfull
SearchByCrn
WhenThereIsAnError
WhenSuccesfull
We don't tend to have that third level of inner classes else where in the code base and just have success and error tests in one inner class, i guess this is something CAS2 do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT, just some suggestions around style/reuse
ac451c1
to
31cca81
Compare
No description provided.